package com.idlefish.flutterboost.action;

import android.text.TextUtils;

import androidx.annotation.NonNull;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.idlefish.flutterboost.FlutterJsonUtil;
import com.idlefish.flutterboost.Messages;
import com.idlefish.flutterboost.intef.MethodCallAction;

import io.flutter.Log;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;

public class MethodActionWebRouteMethod implements MethodCallAction {
    @Override
    public void doAction(Messages.NativeRouterApi api, @NonNull MethodCall methodCall, @NonNull MethodChannel.Result result) {
        Messages.CommonParams params = new Messages.CommonParams();
        String json = FlutterJsonUtil.toJson(methodCall.arguments);
        Log.e("doActionjson",json);
        if(TextUtils.isEmpty(json)){
            return;
        }
        JsonElement jsonElement = JsonParser.parseString(json);
        if(jsonElement.isJsonObject()){
            JsonObject jsonObject = jsonElement.getAsJsonObject();
            if (jsonObject.has("url")){
                params.setPageName(jsonObject.get("url").getAsString());
            }
            api.webRouteMethod(params);
        }
    }
}
